package com.application.lucky.adapter;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.ImageView;

import com.application.lucky.R;
import com.application.lucky.bean.UserBean;
import com.application.lucky.bean.jsonBean.FriendApplyBean;
import com.application.lucky.bean.jsonBean.FriendBean;
import com.application.lucky.config.Config;
import com.application.lucky.request.nav.UrlManager;
import com.qunar.im.ui.util.ProfileUtils;
import com.qunar.im.ui.view.recyclerview.BaseQuickAdapter;
import com.qunar.im.ui.view.recyclerview.BaseViewHolder;

public class NewFriendsAdapter extends BaseQuickAdapter<FriendApplyBean.FriendListBean, BaseViewHolder> {

    public NewFriendsAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, FriendApplyBean.FriendListBean item) {
        FriendBean user = item.getUser();
        if (user != null) {
            helper.setText(R.id.tv_item_new_friend_name, user.getNickName());
        }

        helper.setText(R.id.tv_item_new_friend_add, item.isAdd ? "已添加" : "添加")
                .setText(R.id.tv_item_new_friend_message, "我是" + item.getApplyMessage())
                .setBackgroundRes(R.id.tv_item_new_friend_add, item.isAdd ? R.drawable.shape_button_bg_un : R.drawable.shape_button_bg)
                .addOnClickListener(R.id.tv_item_new_friend_add);
        ImageView view = helper.getView(R.id.iv_item_new_friend_thumb);
        if (!TextUtils.isEmpty(item.getUser().getHeadPic())) {
            ProfileUtils.displayGravatarRoundedCornerByImageSrc((Activity) mContext, UrlManager.getHeadPic(item.getUser().getHeadPic()), view);
        }
    }


    public void upDataItemById(String id) {
        for (int i = 0; i < getData().size(); i++) {
            FriendApplyBean.FriendListBean item = getItem(i);
            if (item != null) {
                if (item.getUser() != null) {
                    if (id.equals(item.getUser().getUserId() + "")) {
                        item.isAdd = true;
                        notifyItemChanged(i);
                    }
                }
            }
        }
    }
}
